package com.yawn.zdproject.controller;

import com.yawn.zdproject.entity.Project;
import com.yawn.zdproject.service.ProjectService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/project")
public class ProjectController {

    @Resource
    private ProjectService projectService;

    @GetMapping("/getOne")
    public Project getOne(String code) {
        return projectService.findOne(code);
    }

    @GetMapping(value = "/getAll", produces = MediaType.APPLICATION_JSON_VALUE)
    public List<Project> getAll() {
        return projectService.findAll();
    }

    @PostMapping("/add")
    public void add(@RequestBody Project project) {
        projectService.save(project);
    }

    @PostMapping("/delete")
    public void delete(@RequestBody Project pro) {
        projectService.delete(pro);
    }

    @PostMapping("/prefer")
    public boolean setPreferPro(String code) {
        return projectService.setPreferPro(code);
    }

    @GetMapping("/prefer")
    public Project getPreferPro() {
        return projectService.getPreferPro();
    }
}
